//
//  ALPS_TRadioListTCell.m
//  Alps
//
//  Created by dllo on 16/6/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_TRadioListTCell.h"

@implementation ALPS_TRadioListTCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.smallView = [[UIImageView alloc] init];
        self.smallView.layer.borderWidth = 1;
        self.smallView.layer.borderColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.00].CGColor;
        [self.contentView addSubview:_smallView];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:16];
        [self.contentView addSubview:_titleLabel];
        
        self.columnLabel = [[UILabel alloc] init];
        self.columnLabel.font = [UIFont systemFontOfSize:13];
        self.columnLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_columnLabel];
        
        self.numberLabel = [[UILabel alloc] init];
        self.numberLabel.font = [UIFont systemFontOfSize:12];
        self.numberLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_numberLabel];
        
        self.lineLabel = [[UILabel alloc] init];
        self.lineLabel.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_lineLabel];
        
        self.playView = [[UIImageView alloc] init];
        self.playView.image = [UIImage imageNamed:@"album_play"];
        [self.contentView addSubview:_playView];
        
        self.listLabel = [[UILabel alloc] init];
        self.listLabel.textColor = [UIColor grayColor];
        self.listLabel.textAlignment = 1;
        self.listLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_listLabel];
        
        
    }
    
    return self;
    
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    [self.listLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(0);
        make.left.equalTo(self.contentView).offset(0);
        make.height.equalTo(self.contentView.height);
        make.width.equalTo(30);
        
    }];
    
    
    [self.smallView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(10);
        make.left.equalTo(self.listLabel.right).offset(5);
        make.height.equalTo(80);
        make.width.equalTo(80);
        
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(10);
        make.left.equalTo(self.smallView.right).offset(10);
        make.height.equalTo(20);
        make.width.equalTo(200);
    }];
    
    [self.columnLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.bottom).offset(10);
        make.left.equalTo(self.smallView.right).offset(10);
        make.height.equalTo(20);
        make.width.equalTo(200);
    }];
    
    [self.numberLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.columnLabel.bottom).offset(10);
        make.left.equalTo(self.smallView.right).offset(10);
        make.height.equalTo(16);
        make.width.equalTo(200);
    }];
    
    [self.lineLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.numberLabel.bottom).offset(10);
        make.left.equalTo(self.contentView).offset(130);
        make.width.equalTo(self.contentView.width);
        make.height.equalTo(1);
    }];
    
    [self.playView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(30);
        make.right.equalTo(self.contentView).offset(-10);
        make.height.equalTo(12);
        make.width.equalTo(12);
    }];
    
}

-(void)setModel:(ALPS_TRadioModel *)model
{
    if (_model != model) {
        _model = model;
        [self.smallView sd_setImageWithURL:[NSURL URLWithString:model.coverLarge] placeholderImage:[UIImage imageNamed:@"PlaceHolder"]];
        self.titleLabel.text = model.name;
        if (model.programName == NULL) {
            self.columnLabel.text = [NSString stringWithFormat:@"直播中: 暂无节目单"];
        }
        else
        {
            self.columnLabel.text = [NSString stringWithFormat:@"直播中: %@", model.programName];
        }
        if (model.playCount < 10000) {
            self.numberLabel.text = [NSString stringWithFormat:@"收听人数: %ld人", model.playCount];
        }
        else
        {
            self.numberLabel.text = [NSString stringWithFormat:@"收听人数: %ld万人", model.playCount / 10000];
        }
    }
    
}






- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
